package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.TmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class TmsController {
    @Autowired
    TmsService tmsService;

    @RequestMapping("/find1")
    public Object find1(String nowDate){
        List<Map> list = tmsService.find1(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("total"));
        return jsonObject;
    }

    //统计各类货物下单金额占比（存储过程）
    @RequestMapping("/find2")
    public Object find2(String nowDate){
        List<Map> list = tmsService.find2(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("name"));
            mapObject.put("value",map.get("zb"));
            dataArray.add(mapObject);
        }
        jsonObject.put("data",dataArray);
        return jsonObject;
    }

    //统计各省份分拣次数
    @RequestMapping("/find4")
    public Object find4(String nowDate){
        List<Map> list = tmsService.find4(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray maoArray = new JSONArray();
        for (Map map : list) {
            JSONObject nameObject = new JSONObject();
            nameObject.put("name",map.get("name"));
            nameObject.put("value",map.get("count"));
            maoArray.add(nameObject);
        }
        dataObject.put("mapData",maoArray);
        dataObject.put("valueName","次数");
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
}
